"""
初始化项目配置

"""
import os
import hou


def scene_was_loaded():
    current_path = hou.getenv('HIP')
    job_path = os.path.split(current_path)[0]
    hou.putenv('JOB',job_path)


scene_was_loaded()

def createProjectSetting():
    root = hou.node("/obj")
    root.createNode("cgai_manager",'CGAI_Manager')


def createNetworkBox():
    root = hou.node("/obj")
    items = root.allItems()
    networkbox_list = ['Asset','Ani','FX','Render']
    sort_key = {'Asset':1,'Ani':2,'FX':3,'Render':4}
    has_list = []
    for i in items:
        if i.name() in networkbox_list:
            has_list.append(i.name())

    set_a = set(networkbox_list)
    set_b = set(has_list)
    delta = set_a^set_b
    delta_list = sorted(list(delta),key = lambda x : sort_key[x])

    posx = 0
    for n in delta_list:
        net_box = root.createNetworkBox(n)
        net_box.setSize(hou.Vector2(10,15))
        net_box.setComment(n)
        net_box.setPosition(hou.Vector2(posx*12 + 3,2))
        posx += 1

def createProjectSetting():
    root = hou.node("/obj")
    items = root.children()
    projectNode = None
    for i in items:
        if i.type().name() == 'cgai_manager':
            projectNode = i

    if not projectNode:
        projectNode = root.createNode("cgai_manager",'CGAI_Manager')
    projectNode.setPosition(hou.Vector2(26.22,21.75))

createNetworkBox()
# createProjectSetting()